Skip to content

Allow custom interpolation patterns for placeholders#319

Closed
voldy wants to merge 1 commit intoruby-i18n:masterfrom
voldy:master
Closed

Allow custom interpolation patterns for placeholders#319
voldy wants to merge 1 commit intoruby-i18n:masterfrom
voldy:master

Conversation

@voldy
Copy link

@voldy voldy commented Jun 22, 2015

Pain

In our project we use %{foo} placeholders for rails back end translations and {{foo}} for ember client. In some cases we need the same translation both at back end and front end which is a pain to support the same translations only because of different interpolation placeholders.

Solution

I added an ability to configure custom interpolation patterns in i18n so that different placeholders can be used:

I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/

@radar
Copy link
Collaborator

radar commented Nov 16, 2016

This will break backwards compatibility for anyone who uses {{foo}} in their translations and they're expecting it to not be interpolated. Going to assign this to the 1.0 milestone.

@radar radar added this to the 1.0.0 milestone Nov 16, 2016
@stereobooster
Copy link
Contributor

This will break backwards compatibility for anyone who uses {{foo}} in their translations and they're expecting it to not be interpolated. Going to assign this to the 1.0 milestone.

But if you do not do this

I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/

nothing is changed for you. This is do not break compatibility. Or I miss something?

@tonytonyjan
Copy link
Contributor

Agree with @stereobooster.

@radar, I do not see any clue that this pull request will break compatibility; instead, @voldy handles backward compatibility very well and makes it customizable, so there is no need to keep pending this feature until v1.0.

@dillonwelch
Copy link
Contributor

@voldy looks like this has a merge conflict now

tonytonyjan added a commit to tonytonyjan/i18n that referenced this pull request Oct 25, 2018
add a new config: `I18n.config.interpolation_patterns`

Usage:

    I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/
    I18n.interpolate("Hello, {{name}}", name: "tonytonyjan")
    # => "Hello, tonytonyjan"

close ruby-i18n#319
tonytonyjan added a commit to tonytonyjan/i18n that referenced this pull request Oct 25, 2018
add a new config: `I18n.config.interpolation_patterns`

Usage:

    I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/
    I18n.interpolate("Hello, {{name}}", name: "tonytonyjan")
    # => "Hello, tonytonyjan"

close ruby-i18n#319
@tonytonyjan
Copy link
Contributor

opened #439 as an improved version of this pull request.

@radar
Copy link
Collaborator

radar commented Oct 25, 2018

Closing this as #439 is more up-to-date.

@radar radar closed this Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants